package org.codeart.order.controller;

import lombok.extern.slf4j.Slf4j;
import org.codeart.common.dto.OrderInfo;
import org.codeart.common.util.R;
import org.codeart.order.mapper.OrderInfoMapper;
import org.codeart.order.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class TestController {
    
    @Value("${server.port}")
    private Integer port;
    
    @Autowired
    private OrderInfoService orderInfoService;
    
    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @GetMapping("/real-time-order/{orderId}")
    public R<Void> dispatchOrder(@PathVariable("orderId") Long orderId) {
        log.info("并发测试, 端口号: {}, orderId: {}", port, orderId);
        OrderInfo orderInfo = orderInfoMapper.selectById(orderId);
        orderInfoService.dispatchRealTimeOrder(orderInfo);
        return R.ok();
    }
}
